package org.demo.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.demo.common.Result;
import org.demo.entity.*;
import org.demo.mapper.*;
import org.demo.service.*;
import org.demo.utils.ThreadLocalUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.time.LocalDate;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class HousesServiceImpl extends ServiceImpl<HousesMapper, Houses> implements IHousesService {
    @Autowired
    private HousesMapper housesMapper;
    @Autowired
    private AppointmentsMapper appointmentsMapper;
    @Autowired
    private IOrderIdService orderIdService;
    @Autowired
    private UsersMapper usersMapper;
    @Autowired
    private CommunityMapper communityMapper;
    @Autowired
    private HousewearMapper housewearMapper;
    @Autowired
    private HousesItemMapper housesItemMapper;
    @Autowired
    private IHousesItemService housesItemService;
    @Autowired
    private INoticeService noticeService;

    @Override
    public void add(HousesDto housesDto) {

        String id = orderIdService.getId("HOUSE");
        housesDto.setId(id);
        HousesItem housesItem = new HousesItem();
        String itemid = orderIdService.getId("HOUSEITEM");
        housesItem.setId(itemid);
        housesItem.setHousesId(id);
        housesItem.setTitle(housesDto.getTitle());
        housesItem.setHousesPic(housesDto.getHousesPic());
        housesItem.setRemake(housesDto.getRemake());
        if (housesDto.getIntermediaryId()!=null){
            Users inter = usersMapper.selectById(housesDto.getIntermediaryId());
            housesItem.setIntermediaryTel(inter.getPhone());
        }
        if (housesDto.getLandlordId()==null){
            Map<String,Object> map = ThreadLocalUtil.get();
            String LandlordId = (String) map.get("id");
            housesDto.setLandlordId(LandlordId);
        }
        if (housesDto.getStatus()==null){
            housesDto.setStatus("0");
        }

        LocalDate today = LocalDate.now();
        ZonedDateTime zdt = today.atStartOfDay(ZoneId.systemDefault());
        Date dateWithoutTime = Date.from(zdt.toInstant());
        housesDto.setPublishTime(today);
//        housesDto.setPublishTime(new Date());

        Houses houses = BeanUtil.copyProperties(housesDto, Houses.class);

        save(houses);
        housesItemService.save(housesItem);

    }

    @Override
    public void addLanHouse(HousesDto housesDto) {
        String id = orderIdService.getId("HOUSE");
        housesDto.setId(id);
        HousesItem housesItem = new HousesItem();
        String itemid = orderIdService.getId("HOUSEITEM");
        housesItem.setId(itemid);
        housesItem.setHousesId(id);
        housesItem.setTitle(housesDto.getTitle());
        housesItem.setRemake(housesDto.getRemake());

        if (housesDto.getLandlordId()==null){
            Map<String,Object> map = ThreadLocalUtil.get();
            String LandlordId = (String) map.get("id");
            housesDto.setLandlordId(LandlordId);
        }
        //当前时间
        LocalDate today = LocalDate.now();
        ZonedDateTime zdt = today.atStartOfDay(ZoneId.systemDefault());
        Date dateWithoutTime = Date.from(zdt.toInstant());
        housesDto.setPublishTime(today);


        Houses houses = BeanUtil.copyProperties(housesDto, Houses.class);

        save(houses);
        housesItemService.save(housesItem);

    }




    @Override
    public boolean update(HousesDto dto) {
        Houses house = BeanUtil.copyProperties(dto, Houses.class);
        house.setUpdateTime(LocalDate.now());
        HousesItem housesItem = housesItemService.lambdaQuery().eq(HousesItem::getHousesId,house.getId()).one();
        housesItem.setTitle(dto.getTitle());
        housesItem.setHousesPic(dto.getHousesPic());
        housesItem.setRemake(dto.getRemake());
        if (dto.getIntermediaryId()!=null){
            Users inter = usersMapper.selectById(dto.getIntermediaryId());
            housesItem.setIntermediaryTel(inter.getPhone());
        }else {
            house.setIntermediaryId("");
            housesItem.setIntermediaryTel("-");
        }
        housesItemMapper.updateById(housesItem);
        return housesMapper.updateById(house)>0;
    }


    @Override
    public void weituoOK(Houses houses) {
        Houses houses1 = housesMapper.selectById(houses.getId());
        houses1.setIntermediaryId(houses.getIntermediaryId());
        houses1.setStatus("1");
        Users users = usersMapper.selectById(houses.getIntermediaryId());
        HousesItem housesItem = housesItemService.lambdaQuery().eq(HousesItem::getHousesId,houses.getId()).one();
        housesItem.setIntermediaryTel(users.getPhone());

        housesMapper.updateById(houses1);
        housesItemMapper.updateById(housesItem);
        String content="您的房产已委托发布";
        noticeService.addNotice(houses1.getIntermediaryId(),houses1.getLandlordId(),houses1.getId(),content,"0","0","0");

    }

    //详情修改
    @Override
    public boolean ItemAllupdate(HousesDto dto) {
        Houses house = BeanUtil.copyProperties(dto, Houses.class);
        house.setUpdateTime(LocalDate.now());
        HousesItem housesItem = housesItemService.lambdaQuery().eq(HousesItem::getHousesId,house.getId()).one();
        housesItem.setTitle(dto.getTitle());
        housesItem.setHousesPic(dto.getHousesPic());
        housesItem.setHousesPic2(dto.getHousesPic2());
        housesItem.setHousesPic3(dto.getHousesPic3());
        housesItem.setHousesPic4(dto.getHousesPic4());
        housesItem.setHousesPic5(dto.getHousesPic5());
        housesItem.setHousesPic6(dto.getHousesPic6());
        housesItem.setRemake(dto.getRemake());
        if (dto.getIntermediaryId()!=null && !dto.getIntermediaryId().equals("")){
            Users inter = usersMapper.selectById(dto.getIntermediaryId());
            housesItem.setIntermediaryTel(inter.getPhone());
        }else {
            house.setIntermediaryId("");
            housesItem.setIntermediaryTel("-");
        }
        housesItemMapper.updateById(housesItem);
        return housesMapper.updateById(house)>0;
    }



    @Override
    public PageBean<HousesDto> Pagelist(Integer pageNum, Integer pageSize, HousesDto house) {
        // 创建 pagebean 对象
        PageBean<HousesDto> pb = new PageBean<>();
        // 开启分页查询
        Page<Houses> page = PageHelper.startPage(pageNum, pageSize);

        house=setPriceRes(house);
        house=setAreaSeach(house);

        List<Houses> houses = housesMapper.list(house);

        List<HousesDto> houseDto = new ArrayList<>();
        for (Houses houseEntity : houses) {
            HousesDto housesDtos = new HousesDto();
            BeanUtils.copyProperties(houseEntity, housesDtos);

            String LanId = houseEntity.getLandlordId();
            if (LanId != null && !LanId.isEmpty()) {
                String LanName = usersMapper.selectById(LanId).getNickname();
                housesDtos.setLandlordName(LanName);
            }

            String IntId = houseEntity.getIntermediaryId();
            if (IntId != null && !IntId.isEmpty()) {
                String IntName = usersMapper.selectById(IntId).getNickname();
                housesDtos.setIntermediaryName(IntName);
            }

            String comId = houseEntity.getCommunityId();
            if (comId != null && !comId.isEmpty()) {
                String comName = communityMapper.selectById(comId).getName();
                housesDtos.setCommunityName(comName);
            }

            String wear = houseEntity.getDescription();
            if (wear != null && !wear.isEmpty()) {
                String wearName = housewearMapper.selectById(wear).getHouseType();
                housesDtos.setDescriptionName(wearName);
            }

            String CusId = houseEntity.getCustomerId();
            if (CusId != null && !CusId.isEmpty()) {
                String CusName = usersMapper.selectById(CusId).getNickname();
                housesDtos.setCustomerName(CusName);
            }
            houseDto.add(housesDtos);
        }

        pb.setTotal(page.getTotal());
        pb.setItems(houseDto);
        return pb;
    }

    @Override
    public List<HousesDto> list(HousesDto house) {
        List<Houses> houses=housesMapper.list(house);
        List<HousesDto> houseDto=new ArrayList<>();
        for (int i = 0; i < houses.size(); i++) {

            HousesDto housesDtos = BeanUtil.copyProperties(houses.get(i), HousesDto.class);

            String LanId= houses.get(i).getLandlordId();
            if (LanId!=null && !LanId.equals("")){
                String LanName = usersMapper.selectById(LanId).getNickname();
                housesDtos.setLandlordName(LanName);
            }

            String IntId= houses.get(i).getIntermediaryId();
            if (IntId!=null && !IntId.equals("")){
                String IntName = usersMapper.selectById(IntId).getNickname();
                housesDtos.setIntermediaryName(IntName);
            }

            String comId = houses.get(i).getCommunityId();
            if (comId!=null && !comId.equals("")){
                String comName = communityMapper.selectById(comId).getName();
                housesDtos.setCommunityName(comName);
            }

            String wear = houses.get(i).getDescription();
            if (wear!=null && !wear.equals("")){
                String wearName = housewearMapper.selectById(wear).getHouseType();
                housesDtos.setDescriptionName(wearName);
            }

            String CusId= houses.get(i).getCustomerId();
            if (CusId!=null && !CusId.equals("")){
                String CusName = usersMapper.selectById(CusId).getNickname();
                housesDtos.setCustomerName(CusName);
            }
            houseDto.add(housesDtos);
        }

        return houseDto;
    }
    @Override
    public PageBean<HousesDto> buylist(Integer pageNum, Integer pageSize, HousesDto house) {
        // 创建 pagebean 对象
        PageBean<HousesDto> pb = new PageBean<>();
        // 开启分页查询
        Page<Houses> page = PageHelper.startPage(pageNum, pageSize);

        house=setPriceBuy(house);
        house=setAreaSeach(house);

        List<Houses> houses = housesMapper.buylist(house);

        List<HousesDto> houseDto = new ArrayList<>();
        for (Houses houseEntity : houses) {
            HousesDto housesDtos = new HousesDto();
            BeanUtils.copyProperties(houseEntity, housesDtos);

            String LanId = houseEntity.getLandlordId();
            if (LanId != null && !LanId.isEmpty()) {
                String LanName = usersMapper.selectById(LanId).getNickname();
                housesDtos.setLandlordName(LanName);
            }

            String IntId = houseEntity.getIntermediaryId();
            if (IntId != null && !IntId.isEmpty()) {
                String IntName = usersMapper.selectById(IntId).getNickname();
                housesDtos.setIntermediaryName(IntName);
            }

            String comId = houseEntity.getCommunityId();
            if (comId != null && !comId.isEmpty()) {
                String comName = communityMapper.selectById(comId).getName();
                housesDtos.setCommunityName(comName);
            }

            String wear = houseEntity.getDescription();
            if (wear != null && !wear.isEmpty()) {
                String wearName = housewearMapper.selectById(wear).getHouseType();
                housesDtos.setDescriptionName(wearName);
            }

            String CusId = houseEntity.getCustomerId();
            if (CusId != null && !CusId.isEmpty()) {
                String CusName = usersMapper.selectById(CusId).getNickname();
                housesDtos.setCustomerName(CusName);
            }
            houseDto.add(housesDtos);
        }

        pb.setTotal(page.getTotal());
        pb.setItems(houseDto);
        return pb;
    }
    @Override
    public PageBean<HousesDto> buyCuslist(Integer pageNum, Integer pageSize, HousesDto house) {
        // 创建 pagebean 对象
        PageBean<HousesDto> pb = new PageBean<>();
        // 开启分页查询
        Page<Houses> page = PageHelper.startPage(pageNum, pageSize);

        String cusId = house.getCustomerId();
        List<Appointments> appointments = appointmentsMapper.selectStuats(cusId);

        house=setPriceBuy(house);
        house=setAreaSeach(house);

        List<Houses> houses = housesMapper.buylist(house);

        List<HousesDto> houseDto = new ArrayList<>();
        for (Houses houseEntity : houses) {
            HousesDto housesDtos = new HousesDto();
            BeanUtils.copyProperties(houseEntity, housesDtos);

            for (int i = 0; i < appointments.size(); i++) {
                if (appointments.get(i).getHouseId().equals(houseEntity.getId())){
                    housesDtos.setEntrustType("1");
                    break;
                }else {
                    housesDtos.setEntrustType("0");
                }
            }
            if (appointments.isEmpty()){
                housesDtos.setEntrustType("0");
            }

            String LanId = houseEntity.getLandlordId();
            if (LanId != null && !LanId.isEmpty()) {
                String LanName = usersMapper.selectById(LanId).getNickname();
                housesDtos.setLandlordName(LanName);
            }

            String IntId = houseEntity.getIntermediaryId();
            if (IntId != null && !IntId.isEmpty()) {
                String IntName = usersMapper.selectById(IntId).getNickname();
                housesDtos.setIntermediaryName(IntName);
            }

            String comId = houseEntity.getCommunityId();
            if (comId != null && !comId.isEmpty()) {
                String comName = communityMapper.selectById(comId).getName();
                housesDtos.setCommunityName(comName);
            }

            String wear = houseEntity.getDescription();
            if (wear != null && !wear.isEmpty()) {
                String wearName = housewearMapper.selectById(wear).getHouseType();
                housesDtos.setDescriptionName(wearName);
            }

            String CusId = houseEntity.getCustomerId();
            if (CusId != null && !CusId.isEmpty()) {
                String CusName = usersMapper.selectById(CusId).getNickname();
                housesDtos.setCustomerName(CusName);
            }


            houseDto.add(housesDtos);
        }

        pb.setTotal(page.getTotal());
        pb.setItems(houseDto);
        return pb;
    }
    @Override
    public PageBean<HousesDto> resCuslist(Integer pageNum, Integer pageSize, HousesDto house) {
        // 创建 pagebean 对象
        PageBean<HousesDto> pb = new PageBean<>();
        // 开启分页查询
        Page<Houses> page = PageHelper.startPage(pageNum, pageSize);

        String cusId = house.getCustomerId();
        List<Appointments> appointments = appointmentsMapper.selectStuats(cusId);

        house=setPriceRes(house);
        house=setAreaSeach(house);

        List<Houses> houses = housesMapper.reslist(house);
        List<HousesDto> houseDto = new ArrayList<>();
        for (Houses houseEntity : houses) {
            HousesDto housesDtos = new HousesDto();
            BeanUtils.copyProperties(houseEntity, housesDtos);

            for (int i = 0; i < appointments.size(); i++) {
                if (appointments.get(i).getHouseId().equals(houseEntity.getId())){
                    housesDtos.setEntrustType("1");
                    break;
                }else {
                    housesDtos.setEntrustType("0");
                }
            }
            if (appointments.isEmpty()){
                housesDtos.setEntrustType("0");
            }

            if (houseEntity.getId()!=null){
                HousesItem housesItem = housesItemService.lambdaQuery().eq(HousesItem::getHousesId,houseEntity.getId()).one();

                housesDtos.setTitle(housesItem.getTitle());
                housesDtos.setHousesPic(housesItem.getHousesPic());
                housesDtos.setRemake(housesItem.getRemake());
            }

            String LanId = houseEntity.getLandlordId();
            if (LanId != null && !LanId.isEmpty()) {
                String LanName = usersMapper.selectById(LanId).getNickname();
                housesDtos.setLandlordName(LanName);
            }

            String IntId = houseEntity.getIntermediaryId();
            if (IntId != null && !IntId.isEmpty()) {
                String IntName = usersMapper.selectById(IntId).getNickname();
                housesDtos.setIntermediaryName(IntName);
            }

            String comId = houseEntity.getCommunityId();
            if (comId != null && !comId.isEmpty()) {
                String comName = communityMapper.selectById(comId).getName();
                housesDtos.setCommunityName(comName);
            }

            String wear = houseEntity.getDescription();
            if (wear != null && !wear.isEmpty()) {
                String wearName = housewearMapper.selectById(wear).getHouseType();
                housesDtos.setDescriptionName(wearName);
            }

            String CusId = houseEntity.getCustomerId();
            if (CusId != null && !CusId.isEmpty()) {
                String CusName = usersMapper.selectById(CusId).getNickname();
                housesDtos.setCustomerName(CusName);
            }



            houseDto.add(housesDtos);
        }

        pb.setTotal(page.getTotal());
        pb.setItems(houseDto);
        return pb;
    }
    @Override
    public PageBean<HousesDto> reslist(Integer pageNum, Integer pageSize, HousesDto house) {
        // 创建 pagebean 对象
        PageBean<HousesDto> pb = new PageBean<>();
        // 开启分页查询
        Page<Houses> page = PageHelper.startPage(pageNum, pageSize);

        house=setPriceRes(house);
        house=setAreaSeach(house);

        List<Houses> houses = housesMapper.reslist(house);
        List<HousesDto> houseDto = new ArrayList<>();
        for (Houses houseEntity : houses) {
            HousesDto housesDtos = new HousesDto();
            BeanUtils.copyProperties(houseEntity, housesDtos);

            if (houseEntity.getId()!=null){
                HousesItem housesItem = housesItemService.lambdaQuery().eq(HousesItem::getHousesId,houseEntity.getId()).one();

                housesDtos.setTitle(housesItem.getTitle());
                housesDtos.setHousesPic(housesItem.getHousesPic());
                housesDtos.setRemake(housesItem.getRemake());
            }

            String LanId = houseEntity.getLandlordId();
            if (LanId != null && !LanId.isEmpty()) {
                String LanName = usersMapper.selectById(LanId).getNickname();
                housesDtos.setLandlordName(LanName);
            }

            String IntId = houseEntity.getIntermediaryId();
            if (IntId != null && !IntId.isEmpty()) {
                String IntName = usersMapper.selectById(IntId).getNickname();
                housesDtos.setIntermediaryName(IntName);
            }

            String comId = houseEntity.getCommunityId();
            if (comId != null && !comId.isEmpty()) {
                String comName = communityMapper.selectById(comId).getName();
                housesDtos.setCommunityName(comName);
            }

            String wear = houseEntity.getDescription();
            if (wear != null && !wear.isEmpty()) {
                String wearName = housewearMapper.selectById(wear).getHouseType();
                housesDtos.setDescriptionName(wearName);
            }

            String CusId = houseEntity.getCustomerId();
            if (CusId != null && !CusId.isEmpty()) {
                String CusName = usersMapper.selectById(CusId).getNickname();
                housesDtos.setCustomerName(CusName);
            }



            houseDto.add(housesDtos);
        }

        pb.setTotal(page.getTotal());
        pb.setItems(houseDto);
        return pb;
    }
    @Override
    public HousesDto selectId (HousesDto housesDto){
        String HouseId = housesDto.getId();
        Houses houses=housesMapper.selectById(HouseId);

        HousesDto housesDtos = BeanUtil.copyProperties(houses, HousesDto.class);

        String LanId= houses.getLandlordId();
        if (LanId!=null && !LanId.equals("")){
            String LanName = usersMapper.selectById(LanId).getNickname();
            housesDtos.setLandlordName(LanName);
        }
        String IntId= houses.getIntermediaryId();
        if (IntId!=null && !IntId.equals("")){
            String IntName = usersMapper.selectById(IntId).getNickname();
            housesDtos.setIntermediaryName(IntName);
        }

        String comId = houses.getCommunityId();
        if (comId!=null && !comId.equals("")){
            String comName = communityMapper.selectById(comId).getName();
            housesDtos.setCommunityName(comName);
        }

        String wear = houses.getDescription();
        if (wear!=null && !wear.equals("")){
            String wearName = housewearMapper.selectById(wear).getHouseType();
            housesDtos.setDescriptionName(wearName);
        }

        String CusId= houses.getCustomerId();
        if (CusId!=null && !CusId.equals("")){
            String CusName = usersMapper.selectById(CusId).getNickname();
            housesDtos.setCustomerName(CusName);
        }

        return housesDtos;
    }
    public HousesDto setAreaSeach(HousesDto housesDto){
        if (housesDto.getArea()!=null){
            if((housesDto.getArea().compareTo(new BigDecimal(7))==0)){
                housesDto.setStartArea(new BigDecimal(0));
                housesDto.setEndArea(new BigDecimal(50));
            }else if((housesDto.getArea().compareTo(new BigDecimal(1))==0)){
                housesDto.setStartArea(new BigDecimal(50));
                housesDto.setEndArea(new BigDecimal(70));
            }else if((housesDto.getArea().compareTo(new BigDecimal(2))==0)){
                housesDto.setStartArea(new BigDecimal(70));
                housesDto.setEndArea(new BigDecimal(80));
            }else if((housesDto.getArea().compareTo(new BigDecimal(3))==0)){
                housesDto.setStartArea(new BigDecimal(80));
                housesDto.setEndArea(new BigDecimal(90));
            }else if((housesDto.getArea().compareTo(new BigDecimal(4))==0)){
                housesDto.setStartArea(new BigDecimal(90));
                housesDto.setEndArea(new BigDecimal(100));
            }else if((housesDto.getArea().compareTo(new BigDecimal(5))==0)){
                housesDto.setStartArea(new BigDecimal(100));
                housesDto.setEndArea(new BigDecimal(150));
            }else if((housesDto.getArea().compareTo(new BigDecimal(6))==0)){
                housesDto.setStartArea(new BigDecimal(150));
                housesDto.setEndArea(new BigDecimal(1000000000));
            }
        }
        return housesDto;
    }

    public HousesDto setPriceRes(HousesDto housesDto){
        if (housesDto.getPrice()!=null){
            if((housesDto.getPrice().compareTo(new BigDecimal(7))==0)){
                housesDto.setStartPrice(new BigDecimal(0));
                housesDto.setEndPrice(new BigDecimal(1000));
            }else if((housesDto.getPrice().compareTo(new BigDecimal(1))==0)){
                housesDto.setStartPrice(new BigDecimal(1000));
                housesDto.setEndPrice(new BigDecimal(1500));
            }else if((housesDto.getPrice().compareTo(new BigDecimal(2))==0)){
                housesDto.setStartPrice(new BigDecimal(1500));
                housesDto.setEndPrice(new BigDecimal(2000));
            }else if((housesDto.getPrice().compareTo(new BigDecimal(3))==0)){
                housesDto.setStartPrice(new BigDecimal(2000));
                housesDto.setEndPrice(new BigDecimal(2500));
            }else if((housesDto.getPrice().compareTo(new BigDecimal(4))==0)){
                housesDto.setStartPrice(new BigDecimal(2500));
                housesDto.setEndPrice(new BigDecimal(3000));
            }else if((housesDto.getPrice().compareTo(new BigDecimal(5))==0)){
                housesDto.setStartPrice(new BigDecimal(3000));
                housesDto.setEndPrice(new BigDecimal(5000));
            }else if((housesDto.getPrice().compareTo(new BigDecimal(6))==0)){
                housesDto.setStartPrice(new BigDecimal(5000));
                housesDto.setEndPrice(new BigDecimal(1000000000));
            }
        }
        return housesDto;
    }
    public HousesDto setPriceBuy(HousesDto housesDto){
        if (housesDto.getPrice()!=null){
            if((housesDto.getPrice().compareTo(new BigDecimal(7))==0)){
                housesDto.setStartPrice(new BigDecimal(0));
                housesDto.setEndPrice(new BigDecimal(200000));
            }else if((housesDto.getPrice().compareTo(new BigDecimal(1))==0)){
                housesDto.setStartPrice(new BigDecimal(200000));
                housesDto.setEndPrice(new BigDecimal(250000));
            }else if((housesDto.getPrice().compareTo(new BigDecimal(2))==0)){
                housesDto.setStartPrice(new BigDecimal(250000));
                housesDto.setEndPrice(new BigDecimal(300000));
            }else if((housesDto.getPrice().compareTo(new BigDecimal(3))==0)){
                housesDto.setStartPrice(new BigDecimal(300000));
                housesDto.setEndPrice(new BigDecimal(350000));
            }else if((housesDto.getPrice().compareTo(new BigDecimal(4))==0)){
                housesDto.setStartPrice(new BigDecimal(350000));
                housesDto.setEndPrice(new BigDecimal(400000));
            }else if((housesDto.getPrice().compareTo(new BigDecimal(5))==0)){
                housesDto.setStartPrice(new BigDecimal(400000));
                housesDto.setEndPrice(new BigDecimal(500000));
            }else if((housesDto.getPrice().compareTo(new BigDecimal(6))==0)){
                housesDto.setStartPrice(new BigDecimal(500000));
                housesDto.setEndPrice(new BigDecimal(1000000000));
            }
        }
        return housesDto;
    }

    @Override
    public Houses detalil(String id) {
        Houses houses = housesMapper.selectById(id);
        return houses;
    }


    @Override
    public void delete(String id) {
        housesMapper.deleteById(id);
        HousesItem housesItem = housesItemService.lambdaQuery().eq(HousesItem::getHousesId,id).one();
        housesItemService.removeById(housesItem);
    }

    @Override
    public void downHouse(Houses houses) {
        Houses house = housesMapper.selectById(houses.getId());
        String HouseId = house.getId();

        house.setStatus("2");
        housesMapper.updateById(house);
    }
}
